<?php 
namespace Weixin\Controller;
use Weixin\Controller\BaseController;
class JsController extends  BaseController{
	
	/**
	 * 通过前段script的方式引入数据
	 */
	public function get_js_ticket(){
		$ticket = $this->weObj->getJsTicket();
		$url = 'http://'.$_SERVER['HTTP_HOST'].'/home/fuwu/index.html';
		$sign = $this->weObj->getJsSign($url);
		echo 'var wxconfig = '.json_encode($sign).';';
		die();
	}
	
	public function imgupload(){
		$m = M('WxImage');
		$_POST['update_time'] = Date('Y-m-d H:i:s');
		$_POST['uid'] = $_SESSION['loginUser']['uid'];
		
		$data = $m->create($_POST);
		if($m->add($data)){
			$this->success('图片上传成功');
		}else{
			$this->error('图片上传失败');
		}
	}
	/**
	 * 根据media_id获取图片临时地址
	 */
	public function get_image_tmpurl(){
		if(!$_REQUEST['media_id']) _apiReturn(0, 'media_id不能为空', $data, $url);
		$data = $this->weObj->getMedia($_REQUEST['media_id'],false);
		_apiReturn(1, '获取成功', $data, $url);
	}
}
?>